<template>
    <div>
      <Card class="clearfix" style="padding-bottom: 50px">
        <p slot="title">
            基础数据类型
        </p>

        <Row>
          <i-col span="24">
            <!-- 数据类型名称 -->
            <i-col span="3" >
                <Input  v-model="typeName"  @on-change="searchTypeName" placeholder="类型名称" icon="search" style="width: 180px" />
            </i-col>
            <i-col span="3">
                <Button  @click="emptySearch" v-bind:style="{width: 90 + 'px' }" type="primary">清空检索</Button>
            </i-col>
        </i-col>
        </Row>

        <br>
            <Row class="margin-top-10 publish-button-con">
                <Button  @click="addData" icon="ios-checkmark" v-bind:style="{ display:access.add, width: 90 + 'px' }" type="primary">新增</Button>
            </Row>
        <br>

        <div>
            <can-edit-table  @selectData="getSelectData" ref="canEditTable" v-model="tableData" :table-data="tableData" :access="access" v-on:delComplete="delComplete" ></can-edit-table>
        </div>
          <Page ref="pages" :total="recordCount" show-total style="float: right; margin-top: 20px" @on-change="searchMethod"></Page>
      </Card>
    </div>

</template>

<script>
import ajax from '../../../../libs/axios.js'
import canEditTable from './components/columnsTable.vue'
import {otherRouter} from '@/router/router'

export default {
    name: 'basictypeindex',
    components: {
        canEditTable
    },
    data () {
        return {
            // 权限设置
            access: {
                add:'',
                edit: false,
                remove: false
            },
            typeName:'',
            tableData: [],
            recordCount: 0,
            showCurrentTableData: false,
            page: ''
        }
    },
    methods: {
        init () {
            let vm = this
            let edit = false
            let remove = false
            otherRouter.children.forEach(item => {
                if (item.name === 'updateBasicType') {
                    edit = true
                }
                if (item.name === 'addBasicType') {
                    vm.access.add = 'block'
                }
                if (item.name === 'removeSymptom') {
                    remove = true
                }
            })
            vm.access.edit = edit
            vm.access.remove = true
            this.searchMethod(1)
        },
        // 新增
        addData () {
            console.log('添加症状数据')
            this.$router.push({
                name: 'addBasicType'
            })
        },
        emptySearch () {
            this.typeName = ''
        },
        //检索类型名称
        searchTypeName(){
            this.searchMethod(1)
        },
        // 检索方法
        searchMethod (page) {
            let url = '/adminapi/basictype/basicTypeList.html'
            let data = {
                typeName:this.typeName,
                pageNumber: page,
                pageSize: 10
            }
            ajax.jsonRes(url, data).then(res => {
                // success
                console.log("***********")
                console.log(res)
                this.tableData = res.list
                this.recordCount = res.recordCount
            }).catch(res => {
                // fail
                console.log('获取症状数据有错误信息')
            })
        },
        getSelectData : function (msg) {
            this.selectData = msg
            console.log(this.selectData)
        },
        delComplete () {
            this.searchMethod(1)
        }
    },
    created () {
        this.init()
    },
    // created 进入页面初始化一次    activated每次进入页面都初始化
    activated () {
        this.init()
    }
}
</script>
